<?php
/**
 * This file contains the translation class
 *
 * PHP version 5
 *
 * @category  PHP
 * @package   PHPMY
 * @author    Sven Ruttloff, www.sruttloff.de <service@sruttloff.de>
 * @copyright 2010 Sven Ruttloff, www.sruttloff.de
 * @license   http://www.sruttloff.de/cms/files/licence_en_lgpl.txt LGPL
 * @version   SVN: $Id: i18n.class.php 135 2010-12-06 12:16:49Z sruttloff@googlemail.com $
 * @link      phpmy
 */
/**
 * translation class
 *
 * @category  PHP
 * @package   PHPMY
 * @author    Sven Ruttloff, www.sruttloff.de <service@sruttloff.de>
 * @copyright 2010 Sven Ruttloff, www.sruttloff.de
 * @license   http://www.sruttloff.de/cms/files/licence_en_lgpl.txt LGPL
 * @link      phpmy
 */
class i18n
{
    /**
     * @var string actual language
     */
    protected $LANGUAGE = 'de';
    /**
     * @var array associative language array
     */
    protected $LARRAY = array ();
    /**
     * @var object db object
     */
    protected $DB = null;
    /**
     * loads a translation file with language extension e.g. .de
     *
     * @param string $language target language
     *
     * @return void
     */
    function __construct ($language = null)
    {
        $this->DB = frontend::getInstance()->getDB();
        return $this->i18nInit($language);
    }

    /**
     * Switch to another language
     *
     * @param string $language language name
     *
     * @return string language name
     */
    public function switchLanguage($language = "")
    {
        return $this->i18nInit($language);
    }
    /**
     * return a translated string from selected language
     *
     * @param string $sentence string to translate
     *
     * @return string
     */
    public function get($sentence = '')
    {
        return $sentence;
    }
    /**
     * alias for get
     *
     * @param string $sentence string to translate
     *
     * @return string
     */
    public function translate($sentence = '')
    {
        return $this->Get($sentence);
    }
    /**
     * translate a float value into foreign format
     *
     * @param string $float         number to convert
     * @param string $thousandLimit default = ., 1000 = 1.000
     *
     * @return string converted number
     */
    public function convertNumber($float, $thousandLimit = '.')
    {
        switch ($this->LANGUAGE)
        {
            case 'de':
                // $float = str_replace('.', ',', $float);
                $float = number_format($float, 2, ',', $thousandLimit);
                break;
            default:
                break;
        }
        return $float;
    }
    /**
     * translate a iso date (YYYY-MM-DD) into lang. dep. date
     *
     * @param string $date date to convert (YYYY-MM-DD)
     *
     * @return string converted date
     */
    public function convertDate($date)
    {
        switch ($this->LANGUAGE)
        {
            case 'de':
                $date = dateIsoToStd($date);
                break;
            default:
                break;
        }
        return $date;
    }
    /**
     * translate a iso date time (YYYY-MM-DD) into lang. dep. date
     *
     * @param string $dateTime date to convert (YYYY-MM-DD HH:MM:SS)
     *
     * @return string converted date
     */
    public function convertDateTime($dateTime)
    {
        $dT = strtotime($dateTime);
        if ($dT === false)
            return $dateTime;
        $dateTime = $dT;
        switch ($this->LANGUAGE)
        {
            case 'de':
                $dateTime = date('d.m.Y H:i:s', $dateTime);
                break;
            default:
                break;
        }
        return $dateTime;
    }
    /**
     * loads a translation file with language extension e.g. .de
     *
     * @param string $language target language
     *
     * @return void
     */
    protected function i18nInit ($language = null)
    {
        if ($language)
            $this->LANGUAGE = strtolower($language);
        return;
    }
    /**
     * if sentence not exists in the transl. table, create this entry in default lang.
     *
     * @param string $sentence string to translate
     *
     * @return string
     */
    protected function createSentence($sentence = '')
    {
        return $sentence;
    }
}